<template>
  <div class="edc_export_wrapper">
    <div class="main_part">
      <div class="header_text">
        <i class="el-icon-data-line"></i>
        <span>数据管理报告</span>
      </div>
      <div class="table_part">
        <el-table :data="edcExportTableList" stripe :header-cell-style="{ background: 'rgba(117, 60, 202, 0.04)' }">
          <el-table-column label="#" type="index" width="50" align="center"> </el-table-column>
          <el-table-column label="名称" prop="name">
            <template v-slot="{ row }">
              <span @click="handleDownloadFile(row)" style="cursor: pointer; color: #007bff">{{ row.name }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 导出 -->
    <div v-if="exportVisible">
      <export-task
        :exportVisible="exportVisible"
        :exportData="exportData"
        @handleExport="handleExport"
        @handleCancel="handleCancel"
      >
      </export-task>
    </div>
  </div>
</template>

<script>
import { edcExportTableList } from './constant'
import exportTask from './components/exportTask.vue'
import { mapActions } from 'vuex'

export default {
  components: {
    exportTask,
  },

  data() {
    return {
      exportVisible: false,
      exportData: {},
      edcExportTableList,
    }
  },

  methods: {
    ...mapActions('reportManagement', ['exoprtExcelDatasetAll', 'exoprtBlankCaseReport']),
    // 导出
    handleDownloadFile(row) {
      if (row.exportLabel && row.exportLabel.length > 0) {
        this.exportData = row
        this.exportVisible = true
      } else {
        this.$message.warning('功能正在开发中，敬请期待~')
        this.exportVisible = false
      }
    },

    // 关闭导出弹窗
    handleCancel() {
      this.exportVisible = false
      this.exportData = {}
    },

    // 导出
    handleExport(data) {
      if (this.exportData.action) {
        this[this.exportData.action]({ data }).then(res => {
          const { code, message } = res
          if (code === 200) {
            this.$message.success(message)
          }
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.edc_export_wrapper {
  background-color: $white;
  height: 100%;

  .main_part {
    padding-top: 12px;
    background-color: $white;

    .header_text {
      .el-icon-data-line {
        margin-left: 12px;
        margin-right: 12px;
      }

      font-weight: bold;
      font-size: 20px;
    }

    .table_part {
      margin-top: 12px;
    }
  }
}
</style>
